package com.yao.spider.proxy.site;

import com.yao.spider.proxy.ProxyListPageParser;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 单耀 on 2017/12/9.
 */
public class ProxyListPageParaserFactory {
    private static Map<String, ProxyListPageParser> map = new HashMap<String, ProxyListPageParser>();
    public static ProxyListPageParser getProxyListPageParser(Class clazz) {
        ProxyListPageParser proxyListPageParser = null;
        String parseName = clazz.getSimpleName();
        if (map.containsKey(parseName)){
            return map.get(parseName);
        } else {
            try {
                ProxyListPageParser parse = (ProxyListPageParser) clazz.newInstance();
                parseName = clazz.getSimpleName();
                map.put(parseName,parse);
                return parse;

            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
